<!-- 增加页面开始 -->


[#macro couponruleAddView]
<div class="model-form">
	<el-page-header @back="goBack" content="增加优惠券">
	</el-page-header>
	<div class="model-content">
		<el-form ref="ruleForm" :rules="rules" :model="form" label-width="160px">
			<el-row :gutter="10">
				<el-col :span="20">
					<el-form-item label="名称" size="mini" prop="name">
						<el-input v-model="form.name" name="name">
						</el-input>
					</el-form-item>

				</el-col>
				<el-col :span="20">
					<el-form-item label="面额" size="mini" prop="money">
						<el-input v-model="form.money" name="money">
							<template slot="append">元</template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="20">
					<el-form-item label="封面" size="mini" prop="logo">
						<avatar v-model="form.logo"></avatar>
					</el-form-item>

				</el-col>
				<el-col :span="20">
					<el-form-item label="商家" size="mini" prop="shop">
						<el-select style="width: 100%;" v-model="form.shop" filterable clearable placeholder="请选择">
							<el-option v-for="item in shopOptions" :key="item.id" :label="item.name" :value="item.id">
							</el-option>
						</el-select>
					</el-form-item>

				</el-col>
				<el-col :span="20">
					<el-form-item label="使用门槛" size="mini" prop="minPrice">
						<div>
							<el-input v-model.number="form.minPrice" name="minPrice">
								<template slot="prepend">满</template>
								<template slot="append">元可用 *填“0”不做限制 </template>
							</el-input>
						</div>

					</el-form-item>

				</el-col>
				<el-col :span="20">
					<el-form-item label="每人限领" size="mini" prop="limitNum">
						<el-input-number v-model="form.limitNum" name="limitNum" type="textarea" :min="0" :max="100">
						</el-input-number>
					</el-form-item>

				</el-col>
				<el-col :span="20">
					<el-form-item label="发放时间" size="mini" prop="sendTime">
						<el-date-picker v-model="form.sendTime" type="datetimerange" value-format="yyyy-MM-dd HH:mm"
							placeholder="选择日期">
						</el-date-picker>
					</el-form-item>

				</el-col>
				<el-col :span="20">
					<el-form-item label="有效期" size="mini" prop="expireType">
						<el-radio v-model="form.expireType" label="date">固定日期</el-radio>
						<el-radio v-model="form.expireType" label="day">自领取当天起</el-radio>
					</el-form-item>
				</el-col>
				<el-col :span="20" v-if="form.expireType=='date'">
					<el-form-item label="优惠券有效期" size="mini" prop="useTime">
						<el-date-picker v-model="form.useTime" type="datetimerange" value-format="yyyy-MM-dd HH:mm"
							placeholder="选择日期">
						</el-date-picker>
					</el-form-item>

				</el-col>
				<el-col :span="20" v-if="form.expireType=='day'">
					<el-form-item label="固定天数" size="mini" prop="useDay">
						<el-input-number v-model="form.useDay" name="useDay" type="textarea" :min="1" :max="999">
						</el-input-number>
					</el-form-item>

				</el-col>
				<el-col :span="20">
					<el-form-item label="卡券库存" size="mini" prop="stock">
						<el-input-number v-model="form.stock" name="stock" type="textarea" :min="1" :max="100000">
							<template slot="append">张 </template>
						</el-input-number>
					</el-form-item>

				</el-col>
				<el-col :span="20">
					<el-form-item label="结算费率" size="mini" prop="takeawayRate">
						<el-input-number v-model="form.takeawayRate" name="takeawayRate" :min="0" :max="100">
							<template slot="append">张 </template>
						</el-input-number>
					</el-form-item>
				</el-col>
				<el-col :span="20">
					<el-form-item label="使用说明" size="mini" prop="note">
						<el-input v-model="form.note" name="note" type="textarea"></el-input>
					</el-form-item>

				</el-col>
				<el-col :span="20">
					<el-form-item label="活动范围" size="mini" prop="couponScope">
						<el-input v-model="form.couponScope" name="couponScope">
						</el-input>
					</el-form-item>

				</el-col>
			</el-row>
			<el-row>
				<el-col :span="24" style="text-align: right;padding-bottom: 20px;padding-top: 20px;">
					<el-button @click="goBack">取消</el-button>
					<el-button type="primary" @click="add">确定</el-button>
				</el-col>
			</el-row>
		</el-form>
	</div>
</div>
[/#macro]

[#macro couponruleAddConfig]
<script type="text/x-template" id="my-couponrule-add">
	[@couponruleAddView /]
</script>
<script type="text/javascript">
	//添加组件开始
	var couponruleAddConfig = {};
	couponruleAddConfig.template = "#my-couponrule-add";
	couponruleAddConfig.methods = config.basicMethod();
	couponruleAddConfig.data = function () {
		return {
			form: {
				name: '',
				logo: '',
				money: '',
				shop: '',
				minPrice: '',
				limitNum: '',
				sendBeginTime: '',
				sendEndTime: '',
				expireType: '',
				useBeginTime: '',
				useEndTime: '',
				useDay: '',
				stock: '',
				note: '',
				couponScope: '',
				sendTime: [],
				useEndTime: ''
			},
			rules: {
				name: [
					{ required: true, message: '请输入名称', trigger: 'blur' }
				],
				money: [
					{ required: true, message: '请输入面额', trigger: 'blur' }
				],
				shop: [
					{ required: true, message: '请输入商家', trigger: 'blur' }
				],
				sendTime: [
					{ required: true, message: '请选择时间', trigger: 'blur' }
				],
				useTime: [
					{ required: true, message: '请选择时间', trigger: 'blur' }
				]
			}
		}
	};
	couponruleAddConfig.mounted = function () {
	}
	couponruleAddConfig.computed = {};
	couponruleAddConfig.computed.shopOptions = function () {
		return this.$store.state.shopOptions;
	};


	couponruleAddConfig.methods.add = function () {
		var self = this;
		this.$refs["ruleForm"].validate(function (valid) {
			if (valid) {
				self.addData();
			} else {
				console.log('error submit!!');
				return false;
			}
		});
	}

	couponruleAddConfig.methods.addData = function () {
		var self = this, data = this.form;
		if (this.deforeAddData) {
			this.deforeAddData();
		}
		if (this.form.useTime!=null && this.form.useTime.length == 2) {
            this.form.useBeginTime = this.form.useTime[0];
            this.form.useEndTime = this.form.useTime[1];
        }
        if (this.form.sendTime!=null && this.form.sendTime.length == 2) {
            this.form.sendBeginTime = this.form.sendTime[0];
            this.form.sendEndTime = this.form.sendTime[1];
        }
		this.postData("${siteurl}tenantRest/couponrule/create.htm", data, function (res) {
			if (res.code == 0) {
				self.$message({
					message: '添加数据成功',
					type: 'success'
				});
				self.$router.go(-1);
			} else {
				self.$message.error(res.msg);
			}
		});
	}

	couponruleAddConfig.destroyed = function () {
		console.log("destroyed add view ");

	}
	var couponruleAddView = Vue.component('add-view', couponruleAddConfig);


</script>
[/#macro]

<!-- 增加页面结束 -->